package org.hot100_1;

import java.util.HashMap;

public class leetcode92 {
    public int majorityElement(int[] nums) {
        if (nums.length==1){
            return nums[0];
        }
        int res = 0;
        int maxTime = 0;

        HashMap<Integer,Integer> map  = new HashMap<>();

        for (int num:nums) {
            if (map.containsKey(num)){
                map.put(num,map.get(num)+1);

                if (map.get(num)>maxTime){
                    maxTime= map.get(num);
                    res=num;
                }

            }else {
                map.put(num,1);
            }
        }

        return res;
    }
}
